export default {
    data() {
        return {
            rLoading: null
        }
    },
    methods: {
        beforeSetData() {
            this.rLoading = this.$loading({
                lock: true,
                text: '加载中，请勿刷新页面',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
        },
        afterSetData() {
            const vm = this;
            // vm.$store.commit("SET_LOADING", false);
            vm.rLoading.close();
        },
        async $awaitApi(apiName, params = {}) {
            const vm = this;
            vm.beforeSetData(apiName);
            const result = await vm.$api(apiName, params);
            vm.afterSetData(apiName);
            return result;
        },
        async $api(apiName, data) {
            const vm = this;
            const result = await vm.$sdk[apiName](data);
            return result;
        },
        async validateForm(formProp = "ruleForm", validate = false) {
            const vm = this;
            if (validate) {
                return validate;
            }
            let refForm = vm.$refs[formProp];
            return new Promise((resolve) => {
                refForm.validate((valid) => {
                    resolve(valid);
                });
            });
        },
    },
}